package com.mxy.myapplication2.java;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.mxy.myapplication2.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义刷新效果  内嵌列表+内嵌非列表
 *
 * @author 马晓勇
 */
public class CustomizedRefreshExampleActivity extends AppCompatActivity {

    private List<Fragment> fragmentList = new ArrayList<>(2);


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customizedrefreshexample);
        fragmentList.add(new CustomizedRefreshNoneListFragment());
        fragmentList.add(new CustomizedRefreshListFragment());
        viewInit();
    }

    private void viewInit() {
        ViewPager viewPager = findViewById(R.id.vp);
        viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
    }


    /**
     * 碎片ViewPager适配器
     */
    private class ViewPagerAdapter extends FragmentPagerAdapter {

        private ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fragmentList.get(i);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }
    }

    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        Log.w("MXY", "CustomizedRefreshExampleActivity onWindowFocusChanged hasFocus = " + hasFocus);
    }
}